import request from '@/service/index.js'
import objectToQueryString from '@/utils/objecToQuery.js'
// 发布活动
export function publishEvent(eventInfo) {
	return request.post({
		url: '/event',
		data: eventInfo
	})
}

// 编辑活动
export function editEvent(event_id, eventInfo) {
	return request.put({
		url: `/event/${event_id}`,
		data: eventInfo
	})
}

// 删除活动
export function deleteEvent(event_id) {
	return request.delete({
		url: `/event/${event_id}`
	})
}

// 查询活动
export function searchEvent(queryInfo) {
	console.log(queryInfo)
	const queryString = objectToQueryString(queryInfo)
	return request.get({
		url: `/event?${queryString}`
	})
}

// 修改活动状态
export function updateEventStatus(event_id, status) {
	return request.put({
		url: `/event/${event_id}/status`,
		params: {
			status
		}
	})
}

// 根据id查询活动
export function searchEventById(event_id) {
	return request.get({
		url: `/event/${event_id}`
	})
}

// 根据id查询参与的人
export function searchJoinUser(event_id) {
	return request.get({
		url: `/event/${event_id}/member`
	})
}

// 报名活动
export function registerEvent(event_id, user_id) {
	return request.post({
		url: `/event/${event_id}/member/${user_id}/join`
	})
}


// 取消报名
export function cancelRegister(event_id, user_id) {
	return request.post({
		url: `/event/${event_id}/member/${user_id}/cancel`
	})
}

// 查询是否为社长

// 根据社团id获取活动
export function searchEventByClubId(club_id) {
	return request.get({
		url: `/event/${club_id}/club`
	})
}